<script lang="ts">
import { defineComponent, ref, watch, inject, reactive } from "vue";
import { Navigation } from "swiper";
import { Swiper, SwiperSlide } from "swiper/vue";
import "swiper/css";
import "swiper/css/navigation";
import overview from "./component/overview.vue";
import highlight from "./component/highlight.vue";
import topswiper from "@/components/topswiper.vue";

import supportItemVue from "@/components/supportItem.vue";
import relatedItemVue from "@/components/relatedItem.vue";
import pageTop from "@/components/relatedItem.vue";
import { useRoute } from "vue-router";
import { } from "@/network/Productapi";
import ContactModal from "@/components/contactModal.vue";
import { getAdvImages, getCompanyDetail, getRandCompanyProduct } from "@/network/api";

export default defineComponent({
  name: "swiper-example-navigation",
  title: "Navigation",
  url: import.meta.url,
  components: {
    Swiper,
    SwiperSlide,
    overview,
    highlight,
    supportItemVue,
    pageTop,
    relatedItemVue,
    topswiper,
    ContactModal,
  },
  async setup(opacity) {
    const Route = useRoute();

    let data = reactive({
      companyDetail: [] as any,
      bannerList: [] as any,
      solutionsType: '' as string,
      typeCard: ref("card") as any,
      carouselType: (Route.query.carouselType ? Route.query.carouselType : '') as any,
      dialogVisible: false,
    });
    data.solutionsType = "loop";


    const solutionsType = ref("");
    const myFn = inject<any>("open");
    // solutionName.value = Route.query.name;

    const CompanyData = (id: any) => {
      getCompanyDetail({
        id: id,
      }).then((res) => {
        data.companyDetail = res.data;

        if (res.data.images) {
          data.bannerList = res.data.images.split(',');
        }
      });
    };

    watch(
      () => Route.query,
      (val: any) => {
        data.companyDetail = []
        data.bannerList = []
        CompanyData(val.id);
      },
      { immediate: true }
    );

    CompanyData(Route.query.id);

    return {
      myFn,
      data,
      modules: [Navigation],
    };
  },
});
</script>

<template>
  <div class="pageBgc">
    <div class="">
      <div class="content companyBox flex flex_column align_center">
        <div class="companyImg scaleImgCard">
          <img v-if="data.companyDetail.logo" :src="data.companyDetail.logo" alt="" class="" />
          <div v-else style="height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    background-color: #fff;">{{ data.companyDetail.alias }}</div>
        </div>
        <div class="companyName secondTitle">{{ data.companyDetail.name }}</div>

        <div class="webUrl"><a :href="data.companyDetail.link" target='_blank'>{{ data.companyDetail.link }}</a></div>

        <div class="contentText describe">
          {{ data.companyDetail.desc }}
        </div>
      </div>
    </div>

    <div
      v-if="data.companyDetail.business_advantages || data.companyDetail.main_business || data.companyDetail.service_direction || data.companyDetail.advantage">
      <div class="content ">
        <el-row :gutter="22" justify="center">
          <el-col :span="6" v-if="data.companyDetail.business_advantages">
            <div class="directionType directionTypeBgc1">
              <div class="title">业务优势</div>
              <div class="span"> {{ data.companyDetail.business_advantages }}</div>
            </div>
          </el-col>
          <el-col :span="6" v-if='data.companyDetail.main_business'>
            <div class="directionType directionTypeBgc2">
              <div class="title">主营业务</div>
              <div class="span">{{ data.companyDetail.main_business }}</div>
            </div>
          </el-col>
          <el-col :span="6" v-if="data.companyDetail.service_direction">
            <div class="directionType directionTypeBgc3">
              <div class="title">采购原料设备</div>
              <div class="span">{{ data.companyDetail.service_direction }}</div>
            </div>
          </el-col>
          <el-col :span="6" v-if="data.companyDetail.advantage">
            <div class="directionType directionTypeBgc4">
              <div class="title">优势产品</div>
              <div class="span">{{ data.companyDetail.advantage }}</div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>

    <div class="" v-if='data.companyDetail.vedios'>
      <div class="content text_center">
        <div class="bigTitle" style="margin-bottom: 80px">宣传视频</div>

        <div class="flex justify_center">
          <div class="video">
            <video :src="data.companyDetail.vedios" controls width="100%" height="100%"></video>
          </div>
        </div>
      </div>
    </div>

    <div v-if="data.bannerList && data.bannerList.length && data.carouselType">
      <div class="content">
        <div style="padding-top: 30px">
          <el-carousel :interval="4000" :type="data.typeCard" height="441px" :initial-index='0'>
            <el-carousel-item v-for="item in data.bannerList" :key="item">
              <div class="loopBox">
                <img :src="item" alt="" />
              </div>
            </el-carousel-item>
          </el-carousel>
        </div>
      </div>
    </div>

    <div v-if="data.companyDetail.product && data.companyDetail.product.length">
      <div class="content text_center">
        <div class="bigTitle" style="margin-bottom: 80px">企业产品</div>

        <div>
          <el-row :gutter="61">
            <el-col :span="8" :xs='24' v-for="item in data.companyDetail.product">
              <div class="productItem  flex flex_column align_center">
                <div class="imgBox scaleImgCard">
                  <img :src="item.value" alt="" class="" />
                </div>
                <div class="contentText">{{ item.label }}</div>
              </div>
            </el-col>
          </el-row>
        </div>


      </div>
    </div>

    <div class="contact" v-if="data.companyDetail.mobile || data.companyDetail.address">
      <div class="btn" @click="data.dialogVisible = true">立即联系</div>
    </div>

    <el-dialog v-model="data.dialogVisible" title="" width="30%">
      <div>
      <div class="flex flex_column align_center" style="margin-bottom: 20px;">
        <div class="companyImg scaleImgCard">
          <img v-if="data.companyDetail.logo" :src="data.companyDetail.logo" alt="" class="" />
          <div v-else style="height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    background-color: #fff;">{{ data.companyDetail.alias }}</div>
        </div>
        <div class="companyName secondTitle">{{ data.companyDetail.name }}</div>
      </div>

        <div v-if="data.companyDetail.address" style="font-size: 22px;">联系地址：<span>{{ data.companyDetail.address }}</span>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<style lang="scss" scoped>
@import url("@/assets/css/content.css");

.loopBox {
  height: 100%;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

.video {
  width: 849px;
  height: 480px;
  border-radius: 10px;
  margin-bottom: 92px;

  video {
    width: 100%;
    height: 100%;
  }
}

.companyBox {
  padding-bottom: 100px;

  .companyImg {
    width: 297px;
    height: 168px;
    object-fit: cover;
    border-radius: 10px;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .companyName {
    margin: 20px 0 27px 0;
  }

  .webUrl {
    a {
      font-size: 18px;
      color: #085dde;
    }
  }
}

.describe {
  text-indent: 2em;
  margin-top: 73px;
}

.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

.breadcrumb {
  border-bottom: 2px solid $auxiliaryColor3;
  padding: 20px 0;
}

.productItem {
  margin-bottom: 71px;

  .imgBox {
    width: 393px;
    height: 215px;
    overflow: hidden;
    border-radius: 10px;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }

  .contentText {
    margin-top: 23px;
  }
}

.content {
  margin: 0 auto;

  .header {
    display: flex;
    width: 100%;
    padding: 44px 0 53px 0;

    .headerLeft {
      width: 450px;
      height: auto;
      margin-right: 30px;
      background-color: #e8f3ff;
      padding: 0 30px;
      border-radius: 20px;

      .headerLeftTitle {
        margin: 60px 0px 20px 0px;
      }

      .headerLeftButton {
        margin: 20px 0;
      }
    }

    .topSwiper {
      display: none;
    }

    .atopSwiper {
      display: block;
    }
  }
}

.directionType {
  padding: 20px;
  height: 100%;
  border-radius: 10px;

  .title {
    font-size: 32px;
    font-weight: bold;
    color: black;
    margin-bottom: 25px;
  }

  .span {
    font-size: 18px;
  }
}

.directionTypeBgc1 {
  background: #EFF9FE;
}

.directionTypeBgc2 {
  background: #F0FBF9;
}

.directionTypeBgc3 {
  background: #FDFBEF;
}

.directionTypeBgc4 {
  background: #FDF5F2;
}

.contact {
  display: flex;
  justify-content: center;

  .btn {
    width: 300px;
    background: #085DDE;
    color: #fff;
    padding: 15px 0;
    border-radius: 10px;
    font-size: 20px;
    cursor: pointer;
    text-align: center;
    margin: 20px 0;
  }
}

@media screen and (max-width: 768px) {
  .productItem {
    .imgBox {
      width: 100%;
    }
  }

  .content {
    .header {
      padding: 30px 0px !important;
      flex-direction: column;

      .headerLeft {
        width: 100%;
        height: 100%;
        padding: 0 30px 20px 30px;
        border-radius: 8px;
        margin-top: 20px;

        .headerLeftTitle {
          margin: 20px 0px 20px 0px;
        }
      }

      .topSwiper {
        display: block;
      }

      .atopSwiper {
        display: none;
      }
    }
  }
}

@media screen and (max-width: 1440px) {
  .headerLeftTitle {
    margin: 10px 0px 20px 0px !important;
  }
}
</style>
